package cn.ly.design.action.clazz;

import java.util.Observable;
import java.util.Observer;

public class JDKObserverTest{
	
	public static void main(String[] args) {
		MySubject2 s = new MySubject2();
		ObserverSub o = new ObserverSub();
		s.addObserver(o);
		s.operate();
	}
	
}


class MySubject2 extends Observable{
	public void operate(){
		System.out.println("MySubject2 changed!!");
		setChanged();//必须调用，用来改变对象状态，这样notifyObservers才能发出通知
		notifyObservers();
	}
}

class ObserverSub implements Observer{

	@Override
	public void update(Observable o, Object arg) {
		System.out.println("ObserverSub recevied!");
	}
	
}